package com.dxy.yesas2020goals.study.partone.disignpattern.explainpattern.calculate;

public class OperatorUtil {

    public static boolean isOperator(String symbol) {
        return (symbol.equals("+") || symbol.equals("-") || symbol.equals("*")||symbol.equals("/") || symbol.equals("(") || symbol.equals(")"));
    }

    public static Interpreter getInterpreter(IArithmeticInterpreter left, IArithmeticInterpreter right,IArithmeticInterpreter left_kuohao, IArithmeticInterpreter right_kuohao, String symbol) {
        if(symbol.equalsIgnoreCase("(")) {
            if (symbol.equals("+")) {
                return new AddInterpreter(left, right,left_kuohao,right_kuohao);
            } else if (symbol.equals("-")) {
                return new SubInterpreter(left, right,left_kuohao,right_kuohao);
            } else if (symbol.equals("*")) {
                return new MultiInterpreter(left, right,left_kuohao,right_kuohao);
            } else if (symbol.equals("/")) {
                return new DivInterpreter(left, right,left_kuohao,right_kuohao);
            }
        } else if(symbol.equalsIgnoreCase(")")) {
            if (symbol.equals("+")) {
                return new AddInterpreter(left, right,left_kuohao,right_kuohao);
            } else if (symbol.equals("-")) {
                return new SubInterpreter(left, right,left_kuohao,right_kuohao);
            } else if (symbol.equals("*")) {
                return new MultiInterpreter(left, right,left_kuohao,right_kuohao);
            } else if (symbol.equals("/")) {
                return new DivInterpreter(left, right,left_kuohao,right_kuohao);
            }
        }
        return null;
    }
}